<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class Base extends Model
{

    /**
     * 状态转换
     * @param $data
     * @param array $map
     * @return mixed
     */
    protected function stateToText(&$data, $map = []){
        foreach ($data as $key => &$row) {
            foreach ($map as $col => $pair) {
                if (isset($row[$col]) && isset($pair[$row[$col]])) {
                    $text = $col . '_text';
                    $row[$text] = $pair[$row[$col]];
                }
            }
        }
        return $data;
    }

    /**
     * 获取上一篇
     * @param $id
     * @return mixed
     */
    protected function prev($id){
        return $this->select(['id','title'])->where('status',1)->where('id', '>', $id)->first();
    }

    /**
     * 获取下一篇
     * @param $id
     * @return mixed
     */
    protected function next($id){
        return $this->select(['id','title'])->where('status',1)->where('id', '<', $id)->first();
    }






}
